package com.shuqi.activity.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shuqi.controller.R;
import com.shuqi.database.model.BookInfo;
/**
 * 购买状态
 * @author zhangpeng
 *
 */
public class CancleBuyAdapter extends BaseAdapter {
    LayoutInflater inflater;
    List<BookInfo> list;
    private Map<String, BookInfo> selectBooks;
    public CancleBuyAdapter(Context context){
         inflater = LayoutInflater.from(context);
    }
    public void setData(List<BookInfo> bookInfos){
        this.list=bookInfos;
    }
    public void setSelectMap(Map<String, BookInfo> selectBooks){
        this.selectBooks = selectBooks;
    }
    @Override
    public int getCount() {
        return list==null?0:list.size();
    }
    
    @Override
    public BookInfo getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHoder holder = null;
        if (convertView != null) {
            view = convertView;
            holder = (ViewHoder) view.getTag();
        } else {
            view = inflater.inflate(R.layout.item_canclebuy_list, parent, false);

            holder = (ViewHoder) view.getTag();
            if (holder == null) {
                holder = new ViewHoder();
                holder.img = (ImageView) view.findViewById(R.id.buy_tag);
                holder.bookName = (TextView) view.findViewById(R.id.book_name);
                view.setTag(holder);
            }
        }
        BookInfo info = list.get(position);
        if(info!=null){
            holder.bookName.setText(info.getBookName());
            if(selectBooks!=null && selectBooks.containsKey(info.getBookId())){
                holder.img.setImageResource(R.drawable.checkbox_item_c);
            }else{
                holder.img.setImageResource(R.drawable.checkbox_item_n);
            }
        }
        return view;
    }
    class ViewHoder{
        private TextView bookName;
        private ImageView img;
    }
}
